#define selecttree(x,placeholder)
<input type="text" id="_#(x.index??)_INPUT" name="#(table??x.table).#(x.tail??)" #(x.required??) #(x.disabled??) #(x.readonly??) placeholder="#(placeholder??)"  class="form-control" autocomplete="off"/>
<input type="hidden" id="_#(x.index??)" data-type="selecttree" name="#(table??x.table).#(x.index??)" value="#(x.value??)" />
	<div id="_#(x.index??)_menuContent" style="display:none;position:absolute;z-index:1000;background-color:white;background-color:#fff;border:1px solid #ccc;width: 85%;height:300px;position: absolute;overflow:scroll;">
		<ul id="_#(x.index??)_ztree" class="ztree"></ul>
	</div>
	#include("/view/common/_ztree.html")
<script type="text/javascript">
	$(function(){
		if("#(x.readonly??)" != "readonly" && "#(x.disabled??)" != "disabled"){
			$("#_#(x.index??)_INPUT").bind("click",function(){
				_#(x.index??)_initZtree();
			});
		}
		if("#(x.init)"=="true"){
			 if($("#_#(x.index??)").val() != ""){
				 initSelectTree($("#_#(x.index??)").val());
			}
		}
	});
	
	function initSelectTree(val){
		$.post("/ztree/getTreeListName",{source:"#(x.source??)", type:"#(x.type??)", where:"#(x.where??)", val:val},function(data){
			if(data.state == 'ok'){
				$("#_#(x.index??)_INPUT").val(data.data);
			}
		}, "json");
	}
	
	function _#(x.index??)_showMenu() {
		var treeObj = $("#_#(x.index??)_INPUT");
		$("#_#(x.index??)_menuContent").slideDown("fast");
		$("body").bind("mousedown", _#(x.index??)_onBodyDown);
	}
	function _#(x.index??)_hideMenu() {
		$("#_#(x.index??)_menuContent").fadeOut("fast");
		$("body").unbind("mousedown", _#(x.index??)_onBodyDown);
	}
	function _#(x.index??)_onBodyDown(event) {
		if (!(event.target.id == "_#(x.index??)_INPUT" || event.target.id == "_#(x.index??)_menuContent" || $(event.target).parents("#_#(x.index??)_menuContent").length>0)) {
			_#(x.index??)_hideMenu();
		}
	}
	
	function _#(x.index??)_initZtree(){
		var setting = {
				check: {
					enable: true,
					#if(x.check == "radio")
						chkStyle: "radio",
						radioType : "all"
					#else
						chkboxType :{ "Y" : "", "N" : "" }
					#end
				},
				data: {
					simpleData: {
						enable: true,
						pIdKey: "pid"
					}
				},
				callback: {
					beforeClick: _#(x.index??)_beforeClick,
					onCheck: _#(x.index??)_onCheck
				}
			};
		
		var zTree = $.fn.zTree.getZTreeObj("_#(x.index??)_ztree");
		if(zTree == null){
			var val = $("#_#(x.index??)").val();
			var type = getTypeName("#(x.type??)","#(x.source??)");
			$.post("/ztree/getTreeList",{source:"#(x.source??)", type:type, where:"#(x.where??)",val:val},function(data){
				if(data.state=='ok'){
					$.fn.zTree.init($("#_#(x.index??)_ztree"), setting, data.data);
					_#(x.index??)_showMenu();
				}
				else{
					layer.msg('数据加载失败!', {icon: 5});
				}
			}, "json");
		}else{
			_#(x.index??)_showMenu();
		}
	}
	
	function _#(x.index??)_beforeClick(treeId, treeNode) {
	/* 	var zTree = $.fn.zTree.getZTreeObj("_#(x.index??)_ztree");
		zTree.checkNode(treeNode, !treeNode.checked, null, true);
		return false; */
	}
	
	function _#(x.index??)_onCheck(e, treeId, treeNode) {
		var zTree = $.fn.zTree.getZTreeObj("_#(x.index??)_ztree"),
		nodes = zTree.getCheckedNodes(true),tnames = "",tvalues = "";
		for (var i=0, l=nodes.length; i<l; i++) {
			var type = getTypeName("#(x.type??)","#(x.source??)");
			if(type.indexOf("dict_")!=-1){
				tvalues += "," + nodes[i].num;
			}else{
				tvalues += "," + nodes[i].id;
			}
			tnames += "," + nodes[i].name;
		}
		tvalues = tvalues.substring(1);
		tnames = tnames.substring(1);
		var treenames = $("#_#(x.index??)_INPUT");
		treenames.val(tnames);
		var treevalues = $("#_#(x.index??)");
		treevalues.val(tvalues);
	}
	
	function getTypeName(type,source){
		if(type.indexOf("selecttreeUser") >= 0){
			type = "user";
		} else if(type.indexOf("selecttreeDept") >= 0){
			type = "dept";
		} else if(type.indexOf("selecttreeRole") >= 0){
			type = "role";
		} else if(type.indexOf("selecttree_") >= 0 || type.indexOf("selecttreeDict") >= 0){
			type = "dict_" + type.replace("selecttree_", "").replace("selecttreeDict", "");
		} else {
			type = "diy_" + source.replace("dict", "dct");
		}
		return type;
	}
	
</script>
#end